const regUsername = /^[a-zA-Z0-9]{8,30}$/ // 用户名效验
const regPassword = /^[a-zA-Z0-9]{6,30}$/ // 密码效验
// console.log(regUsername.test('2343'));

document.querySelector('.btn').addEventListener('click', function (e) {
    e.preventDefault() // 阻止form表单的默认行为
    const form = document.querySelector('.login-form')
    let data = serialize(form, { hash: true, empty: true })
    // console.log(data.username);
    if (regUsername.test(data.username) && regPassword.test(data.password)) {
        axios.post('/login', data)
            .then(res => {
                console.log(res.data);
                pxmu.success('登录成功')
                localStorage.setItem('uname', res.data.username) // 数据剥离，减少一层data
                localStorage.setItem('token', res.data.token)// 数据剥离，减少一层data
                location.href = './index.html'
                

            })
    } else {
        pxmu.fail('效验不通过')
        return

    }

})